package com.July.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @RequestMapping("/user/log")
    public String Login(
            @RequestParam("userName") String userName,
            @RequestParam("password") String password,
            Model model,
            HttpSession session){
        //判断用户名密码是否正确,这儿省略,只要账号密码不为空且密码不为123123则登陆成功!
        if (userName!="" && !"123123".equals(password)){
            session.setAttribute("loginUser",userName);
            return "redirect:/main.html";
        }else{
            //告诉用户登录失败了
            model.addAttribute("msg","用户名或密码错误!");
                return "index";
        }
    }
}
